package com.shareyi.simpleserver.servlet.config;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.shareyi.simpleserver.servlet.PatternUtil;

public class WebAppBean {

	private List<ListenerBean> listenderList;
	private Map<String,FilterBean> filterBeanMap;
	private List<FilterMappingBean> filterMappingList;
	private Map<String,ServletBean> servletBeanMap;
	private List<ServletMappingBean> servletMappingList;
	private List<ConfigParam> welcomFileList;
	private List<ConfigParam> errorPageList;
	private Map<String,String> contextParamMap;
	
	
	public	WebAppBean(){
		listenderList=new LinkedList<ListenerBean>();
		filterBeanMap=new HashMap<String,FilterBean>();
		filterMappingList=new LinkedList<FilterMappingBean>();
		servletBeanMap=new HashMap<String,ServletBean>();
		servletMappingList=new LinkedList<ServletMappingBean>();
		welcomFileList=new LinkedList<ConfigParam>();
		errorPageList=new LinkedList<ConfigParam>();
		contextParamMap=new HashMap<String, String>();
	}

	
	public void addListener(ListenerBean listenerBean){
		listenderList.add(listenerBean);
	}
	
	public void addFilter(FilterBean filterBean){
		filterBeanMap.put(filterBean.getFilterName(),filterBean);
	}
	
	public void addFilterMapping(FilterMappingBean filterMappingBean){
		filterMappingBean.setPatternType(PatternUtil.getPatternType(filterMappingBean.getUrlPattern()));
		filterMappingList.add(filterMappingBean);
	};
	public void addServlet(ServletBean servletBean){
		servletBeanMap.put(servletBean.getServletName(),servletBean);
	};
	public void addServletMapping(ServletMappingBean servletMappingBean){
		servletMappingBean.setPatternType(PatternUtil.getPatternType(servletMappingBean.getUrlPattern()));
		servletMappingList.add(servletMappingBean);
	};
	public void addWelcomFile(ConfigParam welcomFile){
		welcomFileList.add(welcomFile);
	};
	public void addErrorPage(ConfigParam errorPage){
		errorPage.setParamName("errorPage");
		errorPageList.add(errorPage);
	};

	
	

	
	public List<ListenerBean> getListenderList() {
		return listenderList;
	}



	public Map<String, FilterBean> getFilterBeanMap() {
		return filterBeanMap;
	}


	public Map<String, ServletBean> getServletBeanMap() {
		return servletBeanMap;
	}


	public List<FilterMappingBean> getFilterMappingList() {
		return filterMappingList;
	}

	public List<ServletMappingBean> getServletMappingList() {
		return servletMappingList;
	}

	public List<ConfigParam> getWelcomFileList() {
		return welcomFileList;
	}

	public List<ConfigParam> getErrorPageList() {
		return errorPageList;
	}


	public Map<String, String> getContextParamMap() {
		return contextParamMap;
	}


	public void addContextParam( ConfigParam conifgParam) {
		 contextParamMap.put(conifgParam.getParamName(),conifgParam.getParamValue());
	}
	
}
